<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>ES6新特性</title>
</head>

<body>

</body>

<script type="text/javascript">
	//不定参数
	function add(...x) {
		console.log(x);
		x.forEach((v, i) => {
			console.log(i + ": " + v);
		});
		for (v of x) {
			console.log(v);
		}
	}
	add(1,2,3,'a','b','c');

	// 解构
	let [x,y] = getVal();

	function getVal() {
		return [1,2];
	}
	let [name,,age] = ['wayou', 'male', 'secret'];
	console.log(`x = ${x}, y = ${y}`);
	console.log(`name = ${name}, age = ${age}`);

	//字符串模板
	let num = Math.random();
	console.log(`your num is ${num}`);
	console.log('your num is ' + num);

	// 增强的对象字面量
	let human = {
		breathe() {
			console.log('breathing......');
		}
	};
	let worker = {
		__proto__: human,
		company: 'qishon',
		work() {
			console.log('working......');
		}
	};
	human.breathe();
	worker.breathe();
	worker.work();
	console.log(worker.company);

	// class类关键字
	class Animal {
		constructor(name) {
			this.name = name;
		}

		sayName() {
			console.log('my name is ' + this.name);
		}
	}
	class Dog extends Animal {
		constructor(name) {
			super(name);
		}

		say() {
			console.log('my parent is Animal');
		}
	}
	let animal = new Animal('dummy');
	let wayou = new Dog('xiaobai');
	animal.sayName();
	wayou.sayName();
	wayou.say();

	// 箭头操作符
	let array = [1, 2, 3];
	//传统写法
	array.forEach(function (v, i) {
		console.log(i + ": " + v);
	});
	//ES6
	array.forEach((v, i) => console.log(i + ": " + v));
</script>

</html>